//
//  GHCoomentViewController.m
//  GodHorses
//
//  Created by Mac on 2017/11/21.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "GHCoomentViewController.h"
#import "GHXingXingView.h"
#import "STTextView.h"
@interface GHCoomentViewController ()
@property(nonatomic, strong) GHXingXingView                     *desXingxing;
@property(nonatomic, strong) GHXingXingView                     *attXingxing;
@property(nonatomic, strong) GHXingXingView                     *wuliuXingxing;
@property(nonatomic, strong)    STTextView                      *textView;

@end

@implementation GHCoomentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"发表评价";
    [self configSubView];

}

#pragma mark --subView
- (void)configSubView{
    
    UIView * headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    headerView.backgroundColor = [UIColor whiteColor];
    
    UIImageView * bannerImagView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
    [bannerImagView sd_setImageWithURL:[NSURL URLWithString:_model.goodList.firstObject.g_img] placeholderImage:GH_placeHoderImage];
    [headerView addSubview:bannerImagView];
    
    STLabel * desLable = [[STLabel alloc] initWithFrame:CGRectMake(10 + bannerImagView.st_right, bannerImagView.top, 60, 27)
                                                   text:@"描述相符"
                                              textColor:GH_firstTextColor
                                                   font:14
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:desLable];
    self.desXingxing = [[GHXingXingView alloc] initWithFrame:CGRectMake(desLable.right + 3, 0, 220, 44) maxsNum:5];
    [self.desXingxing makeXingXingSelectedWithNum:1];
    self.desXingxing.centerY = desLable.centerY;
    [headerView addSubview:self.desXingxing];
    
    STLabel * attLable = [[STLabel alloc] initWithFrame:CGRectMake(10+bannerImagView.st_right, desLable.bottom  , 60, 27)
                                                   text:@"服务态度"
                                              textColor:GH_firstTextColor
                                                   font:14
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:attLable];
    
    self.attXingxing = [[GHXingXingView alloc] initWithFrame:CGRectMake(desLable.right + 3, 0, 220, 44) maxsNum:5];
    [self.attXingxing makeXingXingSelectedWithNum:1];
    self.attXingxing.centerY = attLable.centerY;
    [headerView addSubview:self.attXingxing];
    
    STLabel * wuliuLable = [[STLabel alloc] initWithFrame:CGRectMake(10 + bannerImagView.st_right, attLable.bottom  , 60, 27)
                                                     text:@"物流服务"
                                                textColor:GH_firstTextColor
                                                     font:14
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentLeft];
    [headerView addSubview:wuliuLable];
    self.wuliuXingxing = [[GHXingXingView alloc] initWithFrame:CGRectMake(desLable.right + 3, 0, 220, 44) maxsNum:5];
    [self.wuliuXingxing makeXingXingSelectedWithNum:1];
    self.wuliuXingxing.centerY = wuliuLable.centerY;
    [headerView addSubview:self.wuliuXingxing];
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(10, bannerImagView.st_bottom + 40, UIScreenWidth - 20, 0.5)];
    line.backgroundColor = GH_lineColor;
    [headerView addSubview:line];
    
    self.textView = [[STTextView alloc] initWithFrame:CGRectMake(10, line.st_bottom + 5, UIScreenWidth - 20, 110)];
    self.textView.placeholder = @"评价一下吧";
    self.textView.placeholderColor = GH_secendTextColor;
    [headerView addSubview:self.textView];
    headerView.height = self.textView.bottom;
    
    self.tableView.tableHeaderView = headerView;
    [self configFooterView];
}
- (void)configFooterView{
    __weak typeof(self) weakSelf =  self;
    UIView * footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 100)];
    footer.backgroundColor = self.tableView.backgroundColor;
    STButton * confimButton = [[STButton alloc] initWithFrame:CGRectMake(30, 0, UIScreenWidth - 60, 44)
                                                        title:@"发布评价"
                                                   titleColor:GH_YellowBackGroundColor
                                                    titleFont:18
                                                 cornerRadius:5
                                              backgroundColor:GH_BlackBackGroundColor
                                              backgroundImage:nil
                                                        image:nil];
    [confimButton setClicAction:^(UIButton *sender) {
        [weakSelf onSelectedCommitButton];
    }];
    confimButton.st_centerY = 50;
    confimButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [footer addSubview:confimButton];
    self.tableView.tableFooterView = footer;
}
#pragma mark --Action Method
- (void)onSelectedCommitButton{
    if (!self.textView.text.length) {
        [SVProgressHUD showErrorWithStatus:@"您还没有评价"];
        return;
    }
    [self sendCommentRequets];
}
#pragma mark --NetWork Method
- (void)sendCommentRequets{
    [SVProgressHUD showWithStatus:@"请稍后"];
    NSMutableDictionary * dic = [NSMutableDictionary new];
    if ([GHUserManger defult].userID.length) {
        [dic setObject:[GHUserManger defult].userID forKey:@"uid"];
    }
    if ([GHUserManger defult].token.length) {
        [dic setObject:[GHUserManger defult].token forKey:@"token"];
    }
    if (!self.model) {
        return;
    }
    [dic setObject:self.textView.text forKey:@"content"];
    [dic setObject:self.model.oriderID forKey:@"o_id"];
    [dic setObject:self.model.goodList.firstObject.g_id forKey:@"g_id"];
    [dic setObject:@(self.desXingxing.chosedNum) forKey:@"star_describe"];
    [dic setObject:@(self.attXingxing.chosedNum) forKey:@"star_serve"];
    [dic setObject:@(self.wuliuXingxing.chosedNum) forKey:@"star_logistics"];
    [[STNetWrokManger defaultClient] requestWithPath:@"http://test.smqyp.com/Api/order/add_comment"
                                              method:STHttpRequestTypePost
                                          parameters:dic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD showSuccessWithStatus:@"评价成功"];
                                                 [self.navigationController popViewControllerAnimated:YES];
                                                 
                                             } failure:^(NSString *stateCode, STError *error) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                             }];
}
@end

